package com.hh.eduservice.controller;


import com.hh.commonutils.Result;
import com.hh.eduservice.entity.vo.CourseVo;
import com.hh.eduservice.entity.vo.PublishVo;
import com.hh.eduservice.mapper.EduCourseMapper;
import com.hh.eduservice.service.EduCourseService;
import com.hh.vo.CourseVoGloabl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author huhuan
 * @since 2021-10-20
 */
@RestController
@RequestMapping("/eduservice/edu_course")
public class EduCourseController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduCourseMapper courseMapper;

    @PostMapping("/addCourse")
    public Result addCourse(@RequestBody CourseVo courseVo){
        String courseId = courseService.addCourse(courseVo);
        return Result.success().data("courseId",courseId);
    }

    @PostMapping("/updateCourse")
    public Result updateCourse(@RequestBody CourseVo courseVo){
        String courseId = courseService.updateCourse(courseVo);
        return Result.success().data("courseId",courseId);
    }

    @GetMapping("/getCourseById/{id}")
    public Result getCourseById(@PathVariable String id, String memberId){
        HashMap map = courseService.getCourseById(id,memberId);
        return Result.success().data(map);
    }

    @GetMapping("/getCourseByIdFeign/{id}")
    public CourseVoGloabl getCourseByIdFeign(@PathVariable String id){
        CourseVo courseVoById = courseMapper.getFrontCourseVoById(id);
        CourseVoGloabl courseVoGloabl = new CourseVoGloabl();
        BeanUtils.copyProperties(courseVoById, courseVoGloabl);
        return courseVoGloabl;
    }

    @GetMapping("/getPublishMessageByCourseId/{courseId}")
    public Result getPublishMessageByCourseId(@PathVariable String courseId){
        PublishVo publishVo = courseService.getPublishMessage(courseId);
        return Result.success().data("publishVo", publishVo);
    }

    @GetMapping("publishCourse/{id}")
    public Result publishCourse(@PathVariable String id){
        courseService.publishCourse(id);
        return Result.success();
    }
}

